<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="员工姓名" prop="name">
            <el-input
                    v-model="queryParams.name"
                    placeholder="请输入员工姓名"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
            />
      </el-form-item>
      <el-form-item label="手机号码" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptName">
        <el-input
                v-model="queryParams.deptName"
                placeholder="请输入部门"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位" prop="title">
                        <el-input
                                v-model="queryParams.title"
                                placeholder="请输入职位"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
      <el-form-item label="工号" prop="jobNumber">
                        <el-input
                                v-model="queryParams.jobNumber"
                                placeholder="请输入工号"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
      <el-form-item label="是否主管" prop="isDeptManageList">
        <el-input
                v-model="queryParams.isDeptManageList"
                placeholder="请输入是否主管(是/否)"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
          <el-input
                  v-model="queryParams.email"
                  placeholder="请输入邮箱"
                  clearable
                  size="small"
                  @keyup.enter.native="handleQuery"
          />
      </el-form-item>
      <el-form-item label="分机号" prop="extNumber">
        <el-input
                v-model="queryParams.extNumber"
                placeholder="请输入分机号"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="办公地点" prop="workStation">
        <el-input
                v-model="queryParams.workStation"
                placeholder="请输入办公地点"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
        />
      </el-form-item>
          <el-form-item label="入职时间" prop="hiredDate">
                        <el-input
                                v-model="queryParams.hiredDate"
                                placeholder="请输入入职时间"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
                 <el-form-item label="激活状态" prop="active">
                        <el-input
                                v-model="queryParams.active"
                                placeholder="请输入激活状态"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
           <el-form-item label="归属组织" prop="exclusiveOrgName">
            <el-input
                    v-model="queryParams.exclusiveOrgName"
                    placeholder="请输入归属组织"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
            />
            </el-form-item>
        <el-form-item label="角色" prop="lableJson">
            <el-input
                    v-model="queryParams.lableJson"
                    placeholder="请输入角色"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    v-hasPermi="['system:info:add']"
            >新增</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-button
                    type="success"
                    icon="el-icon-edit"
                    size="mini"
                    :disabled="single"
                    @click="handleUpdate"
                    v-hasPermi="['system:info:edit']"
            >修改</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-button
                    type="danger"
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['system:info:remove']"
            >删除</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-button
                    type="warning"
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['system:info:export']"
            >导出</el-button>
        </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="钉钉员工id" align="center" prop="staffId" />
              <el-table-column label="员工姓名" align="center" prop="name" />
              <el-table-column label="手机号码" align="center" prop="mobile" />
              <el-table-column label="部门" align="center" prop="deptName" />
              <el-table-column label="职位" align="center" prop="title" />
              <el-table-column label="工号" align="center" prop="jobNumber" />
              <el-table-column label="是否主管(是/否)" align="center" prop="isDeptManageList" />
              <el-table-column label="办公地点" align="center" prop="workStation" />
              <el-table-column label="入职时间" align="center" prop="hiredDate" />
              <el-table-column label="激活状态" align="center" prop="active" />
              <el-table-column label="角色" align="center" prop="lableJson" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:info:edit']"
                >修改</el-button>
                <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.row)"
                        v-hasPermi="['system:info:remove']"
                >删除</el-button>
            </template>
        </el-table-column>
    </el-table>

    <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="钉钉员工id" prop="staffId">
        <el-input v-model="form.staffId" placeholder="请输入钉钉员工id" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="name">
        <el-input v-model="form.name" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
        <el-input v-model="form.mobile" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="部门" prop="deptName">
        <el-input v-model="form.deptName" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="职位" prop="title">
        <el-input v-model="form.title" placeholder="请输入职位" />
        </el-form-item>
        <el-form-item label="工号" prop="jobNumber">
        <el-input v-model="form.jobNumber" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="是否主管(是/否)" prop="isDeptManageList">
        <el-input v-model="form.isDeptManageList" placeholder="请输入是否主管(是/否)" />
        </el-form-item>
        <el-form-item label="直属主管UserID" prop="manageStaffId">
        <el-input v-model="form.manageStaffId" placeholder="请输入直属主管UserID" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
        <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="分机号" prop="extNumber">
        <el-input v-model="form.extNumber" placeholder="请输入分机号" />
        </el-form-item>
        <el-form-item label="办公地点" prop="workStation">
        <el-input v-model="form.workStation" placeholder="请输入办公地点" />
        </el-form-item>
                                      <el-form-item label="入职时间" prop="hiredDate">
        <el-input v-model="form.hiredDate" placeholder="请输入入职时间" />
        </el-form-item>
        <el-form-item label="激活状态" prop="active">
        <el-input v-model="form.active" placeholder="请输入激活状态" />
        </el-form-item>
        <el-form-item label="归属组织" prop="exclusiveOrgName">
        <el-input v-model="form.exclusiveOrgName" placeholder="请输入归属组织" />
        </el-form-item>
        <el-form-item label="登录id" prop="loginId">
        <el-input v-model="form.loginId" placeholder="请输入登录id" />
        </el-form-item>
        <el-form-item label="初始密码" prop="initPassword">
        <el-input v-model="form.initPassword" placeholder="请输入初始密码" />
        </el-form-item>
        <el-form-item label="角色" prop="lableJson">
        <el-input v-model="form.lableJson" placeholder="请输入角色" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/ddUserInfo";

    export default {
        name: "Info",
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 总条数
                total: 0,
                // 【请填写功能名称】表格数据
                    infoList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                                                                            staffId: undefined,
                                                                                                    name: undefined,
                                                                                                    mobile: undefined,
                                                                                                    deptName: undefined,
                                                                                                    title: undefined,
                                                                                                    jobNumber: undefined,
                                                                                                    isDeptManageList: undefined,
                                                                                                    manageStaffId: undefined,
                                                                                                    email: undefined,
                                                                                                    extNumber: undefined,
                                                                                                    workStation: undefined,
                                                                                                                                                hiredDate: undefined,
                                                                                                    active: undefined,
                                                                                                    exclusiveOrgName: undefined,
                                                                                                    loginId: undefined,
                                                                                                    initPassword: undefined,
                                                                                                    lableJson: undefined
                                                            },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }
            };
        },
        created() {
            this.getList();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
        methods: {
            /** 查询【请填写功能名称】列表 */
            getList() {
                this.loading = true;
                listInfo(this.queryParams).then(response => {
                    this.infoList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                                                                            staffId: undefined,
                                                                                                    name: undefined,
                                                                                                    mobile: undefined,
                                                                                                    deptName: undefined,
                                                                                                    title: undefined,
                                                                                                    jobNumber: undefined,
                                                                                                    isDeptManageList: undefined,
                                                                                                    manageStaffId: undefined,
                                                                                                    email: undefined,
                                                                                                    extNumber: undefined,
                                                                                                    workStation: undefined,
                                                                                                    remark: undefined,
                                                                                                    hiredDate: undefined,
                                                                                                    active: undefined,
                                                                                                    exclusiveOrgName: undefined,
                                                                                                    loginId: undefined,
                                                                                                    initPassword: undefined,
                                                                                                    lableJson: undefined
                                                            };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.staffId)
                this.single = selection.length!=1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加【请填写功能名称】";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const staffId = row.staffId || this.ids
                getInfo(staffId).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改【请填写功能名称】";
                });
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.staffId != undefined) {
                            updateInfo(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("修改成功");
                                    this.open = false;
                                    this.getList();
                                } else {
                                    this.msgError(response.msg);
                                }
                            });
                        } else {
                            addInfo(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("新增成功");
                                    this.open = false;
                                    this.getList();
                                } else {
                                    this.msgError(response.msg);
                                }
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const staffIds = row.staffId || this.ids;
                this.$confirm('是否确认删除【请填写功能名称】编号为"' + staffIds + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function() {
                    return delInfo(staffIds);
                }).then(() => {
                    this.getList();
                    this.msgSuccess("删除成功");
                }).catch(function() {});
            },
            /** 导出按钮操作 */
            handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function() {
                    return exportInfo(queryParams);
                }).then(response => {
                    this.download(response.msg);
                }).catch(function() {});
            }
        }
    };
</script>
